package com.pachong.android.baseuicomponent.activity;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import com.pachong.android.baseuicomponent.R;
import com.pachong.android.baseuicomponent.refreshable.IRefreshable;
import com.pachong.android.baseuicomponent.refreshable.OnRefreshListener;
import com.pachong.android.baseuicomponent.refreshable.pullrefresh.PullableRefreshViewHelper;

public abstract class PullableListActivity extends BaseListAcivity implements IRefreshable {
    /**
     * 下拉刷新的辅助类
     */
    private PullableRefreshViewHelper mRefreshViewHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        mRefreshViewHelper = new PullableRefreshViewHelper(this, this);
        super.onCreate(savedInstanceState);

    }

    @Override
    public View createRecyclerContentView(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.common_pullable_recyclerview_content, null);
        RecyclerView rv = (RecyclerView) view.findViewById(R.id.pullableRecycleView);
        setRecyclerView(rv);
        View refreshView = view.findViewById(R.id.refreshView);
        mRefreshViewHelper.initRefreshView(refreshView, this);
        return view;
    }


    /**
     * 回调方法，开始刷新
     */
    @Override
    public void onStartRefreshing() {
    }


    /**
     * 隐藏刷新控件
     */
    @Override
    public void hideRefreshView() {
        mRefreshViewHelper.hideRefreshView();
    }


    /**
     * 显示刷新控件
     */
    @Override
    public void showRefreshView() {
        mRefreshViewHelper.showRefreshView();
    }


    /**
     * 设置是否需要下拉刷新的功能
     *
     * @param enable
     */
    @Override
    public void setPullToRefreshEnable(boolean enable) {
        mRefreshViewHelper.setPullToRefreshEnable(enable);
    }

    /**
     * 设置向下滑动刷新的listener
     * user一般不需要设置这个东西，回调onStartRefreshing足够了。
     *
     * @param listener
     */
    @Override
    public void setOnRefreshListener(OnRefreshListener listener) {
        mRefreshViewHelper.setOnRefreshListener(listener);
    }


}
